package com.briup.jz.web.controller;

import java.util.List;

import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.jz.bean.Article;
import com.briup.jz.bean.extend.ArticleExtend;
import com.briup.jz.service.IArticleService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(description="资讯文章相关接口")
@Validated
@RestController
@RequestMapping("/article")

//类
public class ArticleController {

    @Autowired
    private IArticleService articleService;

    @ApiOperation(value = "查询所有资讯")
    @GetMapping("query")
    public Message query(String title,String status,Long categoryId){
        List<Article> list = articleService.query(title,status,categoryId);
        return MessageUtil.success(list);
    }
    
    @ApiOperation(value = "级联查询所有资讯")
    @GetMapping("queryCascade")
    public Message queryCascade(String title,String status,Long categoryId,Long authorId){
        List<ArticleExtend> list = articleService.queryCascade(title,status,categoryId,authorId);
        return MessageUtil.success(list);
    }

    
    @ApiOperation(value = "通过id删除")
    @GetMapping("deleteById")
    @ApiImplicitParams({
        @ApiImplicitParam(name="id",value = "主键",paramType = "query", required=true),
    })
    public Message deleteById(@NotNull Long id){
    	articleService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value = "保存或更新文章分类信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "主键",paramType = "form"),
            @ApiImplicitParam(name="title",value = "标题",paramType = "form",required = true),
            @ApiImplicitParam(name="content",value = "内容",paramType = "form",required = true),//必需填的要加required
            @ApiImplicitParam(name="cover",value = "缩略图",paramType = "form"),
            @ApiImplicitParam(name="category_id",value = "分类id",paramType = "form"),
            @ApiImplicitParam(name="author_id",value = "作者id",paramType = "form"),
            @ApiImplicitParam(name="status",value = "状态",paramType = "form"),
            //@ApiImplicitParam(name="read_times",value = "阅读时间",paramType = "form"),
            //@ApiImplicitParam(name="thump_up",value = "点赞数",paramType = "form"),
            //@ApiImplicitParam(name="project_id",value = "项目id",paramType = "form"),
    })
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Article article){
    	articleService.saveOrUpdate(article);
        return MessageUtil.success("更新成功");
    }
}

